//统一管理项目用户相关的接口
import request from '@/utils/request'

// 定义接口响应类型
interface LoginResponse {
  code: number
  message: string
  data: {
    token: string
  }
}

interface UserInfoResponse {
  code: number
  message: string
  data: {
    name: string
    avatar: string
    roles: string[]
  }
}

interface LogoutResponse {
  code: number
  message: string
}

//项目用户相关的请求地址
enum API {
  LOGIN_URL = '/user/login',
  USERINFO_URL = '/admin/acl/index/info',
  LOGOUT_URL = '/admin/acl/index/logout',
}

// 登录请求参数类型
interface LoginParams {
  username: string
  password: string
}

//对外暴露请求函数
//登录接口方法
export const reqLogin = (data: LoginParams) => {
  return request.post<LoginParams, LoginResponse>(API.LOGIN_URL, data)
}

//获取用户信息接口方法
export const reqUserInfo = () => {
  return request.get<null, UserInfoResponse>(API.USERINFO_URL)
}

//退出登录
export const reqLogout = () => {
  return request.post<null, LogoutResponse>(API.LOGOUT_URL)
}
